package com.sun.app.service.app;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.sun.app.service.BaseService;
import com.sun.util.AppResult;

public class TipService extends BaseService {

	private static final String GET_TIP_CATALOG = "SELECT TIPID,TIPNAME FROM C_TIP WHERE STATE = 0 AND PARENTID = 0";

	public List getRegisterTIPCatalog() {

		return jt.queryForList(GET_TIP_CATALOG);
	}

	private static final String GET_HOT_TIP = "SELECT TIPID,TIPNAME FROM C_TIP WHERE COUNT > 0 ORDER BY COUNT LIMIT 10";

	public List getRegHotTIP() {
		return jt.queryForList(GET_HOT_TIP);
	}

	private static final String GET_CHILD_TIP_REG = "SELECT TIPID,TIPNAME FROM C_TIP WHERE PARENTID = ?";

	public AppResult getChildTip(HttpServletRequest request) {
		System.out.println("这里");
		AppResult r = new AppResult();
		String pid = request.getParameter("parendid");
		List list = jt.queryForList(GET_CHILD_TIP_REG, pid);
		r.setResult(list);
		r.setTotleCount(list.size());
		return r;
	}

	public static final String ADD_USER_TIP_REG = "insert into c_tip(SESSIONID,TIPNAME,STATE,PARENTID,DATELINE,COUNT)values(?,?,?,?,now(),?)";
	
	public AppResult addRegUserTip(HttpServletRequest request) {
		System.out.println("添加tip");
		Integer max = getMax("TIPID", "c_tip");
		max++;
		AppResult r = new AppResult();
		String sessionId = request.getSession().getId();
		System.out.println(sessionId);
		String tipName = request.getParameter("tipName");
		int update = jt.update(ADD_USER_TIP_REG, sessionId, tipName, 1, 0, 0);
		if (update > 0) {
			r.setStatus(200);
			Map map = new HashMap();
			map.put("tipId", max);
			map.put("msg", "success");
			r.setResult(map);
		} else {
			r.setStatus(300);
			r.setResult("error");
		}

		return r;
	}

	@Override
	public Integer add(HttpServletRequest request, String ip) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer delete(HttpServletRequest request, String ip) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer update(HttpServletRequest request, String ip) {
		// TODO Auto-generated method stub
		return null;
	}

}
